package jt.classic.app.hys.hysyd;

import jt.classic.system.ISystem;
import jt.classic.system.SimpleManager;
import jt.classic.system.group.GroupManager;
import jt.classic.system.group.IGroup;
import jt.classic.system.module.IMenu;
import jt.classic.system.module.IModule;
import jt.classic.system.module.impl.IMenuImpl;
import jt.classic.system.module.impl.IModuleImpl;
import jt.classic.system.role.IRole;
import jt.classic.system.role.RoleManager;
import jt.classic.system.user.IUser;
import jt.classic.system.user.impl.IUserImpl;

import org.limp.basework.SimpleBean;
import org.limp.basework.SimpleBeanProcessor;
import org.limp.basework.Table;
import org.limp.basework.analyzer.TableRegisterCenter;
import org.limp.basework.impl.SimpleBeanImpl;
import org.limp.basework.processor.SingleBeanProcessor;

import org.limp.mine.EncryptTool;

import java.sql.Connection;

import java.util.List;
import java.util.Map;


/**
 * 用户管理者
 * 
 *  @author zhuhaijie
 *
 */
public final class HysydManager extends SimpleManager {
    public HysydManager(Connection conn) {
        super(conn);
    }

    public HysydManager() {
        super();
    }

    /**
     * 根据会议室id 获得该会议 特定日期会议室的预定情况。
     * @param date 20090208
     * @param --- kssj 20090208  000000
     * @param --- jssj 20090208  235959
     * @param id
     * @return
     */
    public List getHysydListById(String id, String date) {
        List list;
        String kssj = date + "235959";
        String jssj = date + "235959";
        String sql =
            "SELECT a.*,b.HYS_MC,b.HYS_ID FROM APP_H_HYSYD a inner join APP_H_HYSZY b on a.HYSYD_HYSID = b.HYS_ID AND b.HYS_ID=" +
            id + " and a.HYSYD_KSSJ <= '" + date + "235959" +
            "' AND a.HYSYD_JSSJ >= '" + date + "00000" +
            "' AND HYSYD_SPZT = 1 ORDER BY HYSYD_ID ASC";

        list = this.trimmer.searchMultiData(sql);

        return list;
    }

    /**
     * 还没有过滤用户所属公司的会议室
     * @param id
     * @return
     */
    public List getHyszyListById(IUser user) {
        List list;

        String sql = "SELECT HYS_MC,HYS_ID FROM APP_H_HYSZY ";

        if (ISystem.isAdmin(user)) {
            //donothing
        } else {
            if (user.igroup() != null) {
                String gname = user.igroup().ibranchgroup(0);
                sql += (" WHERE HYS_GSID_NAME = '" + gname + "'");
            }
        }

        sql += " ORDER BY HYS_ID ASC";

        list = this.trimmer.searchMultiData(sql);

        return list;
    }

    public Map gethysydById(String id) {
        // TODO Auto-generated method stub
        String sql = "SELECT * FROM APP_H_HYSYD where HYSYD_ID=" + id;

        Map map = this.trimmer.searchSingleData(sql);

        return map;
    }

    /**
     * 获得用户  列表 map
     * @return
     */
    public Map getUserMap() {
        // TODO Auto-generated method stub
        String sql = "SELECT * FROM ISYS_USER";
        Map map = this.trimmer.searchSymmetricalData(sql, "ID", "NAME");

        return map;
    }

    /**
     * 所有会议室资源
     * @return List
     */
    public List getHyszy() {
        // TODO Auto-generated method stub
        String sql = "SELECT * FROM APP_H_HYSZY";
        List list = this.trimmer.searchMultiData(sql);

        return list;
    }

    /**
     * 用户可使用的会议室资源
     * @param user
     * @return List
     */
    public List getHyszy(IUser user) {
        // TODO Auto-generated method stub
        StringBuffer where = new StringBuffer(" WHERE 1=1 ");

        if (ISystem.isAdmin(user)) {
            //donothing
        } else if (ISystem.matchrole(user, "user")) {
            if (user.igroup() != null) {
                String gname = user.igroup().ibranchgroup(0);
                where.append(" AND HYS_GSID_NAME = '" + gname + "' ");
            } else {
                where.append(" AND HYS_GSID_NAME = 'noname' ");
            }
        } else {
            where.append(" AND CREATE_USER = '" + user.id() + "' ");
        }

        String sql = "SELECT * FROM APP_H_HYSZY " + where.toString();
        List list = this.trimmer.searchMultiData(sql);

        return list;
    }

    /**
     * 批量删除预定
     * @param ids 用户ID
     */
    public void deleteS(String ids) {
        String sql = "DELETE FROM APP_H_HYSYD WHERE HYSYD_ID IN (" + ids + ")";
        this.trimmer.execute(sql);
    }

    public boolean hysyd_sp(String hysyd_id, String hysyd_spzt,
        String hysyd_spyj) {
        // TODO Auto-generated method stub

        /*String sql =
        UPDATE APP_H_HYSYD
        SET HYSYD_SPYJ = <HYSYD_SPYJ, varchar(500),> ,HYSYD_SPZT = <HYSYD_SPZT, int,>,UPDATE_DATE = <UPDATE_DATE, varchar(20),>,UPDATE_USER = <UPDATE_USER, int,>
        WHERE HYSYD_ID=<搜索条件,,>*/
        return true;
    }
}
